//
//  CTVIconPreviewController.m
//  Channltv
//
//  Created by Bruno Keymolen on 02/08/07.
//  Copyright 2007 channl.tv All rights reserved.
//

#import "CTVIconPreviewController.h"


@implementation CTVIconPreviewController




- (id)initWithScene: (BRRenderScene *) scene andImage:(CGImageRef)img{
	return [self initWithScene:scene andImage:img andYRotation:0.0f];
}

- (id)initWithScene: (BRRenderScene *) scene andImage:(CGImageRef)img andYRotation:(float)rotation{
    if ( [super initWithScene: scene] == nil ){
        return ( nil );
	}
	
	/*
	 * Image
	 */
	
	_image = [[BRImageControl alloc] initWithScene: [self scene]];
//	   if ( fade == YES )
//        [_image setAlphaValue: 1.0f];
    [_image setReflectionAmount: 0.10f];
    [_image setReflectionOffset: 0.02f];
	[_image setYRotation:rotation];	
    [_image setImage: img];
	
	NSRect masterFrame = [[self masterLayer] frame];
    NSRect frame = masterFrame;
    	
	
	frame.size = [_image pixelBounds];
	//Resize frame to 70% of the height or width (biggest size counts)
	if(frame.size.width > frame.size.height){
		//Width is biggest, use 70% of the available width space (keep aspect ratio)
		float oriWidth = frame.size.width;
		float availableWidth = (masterFrame.size.width - masterFrame.origin.x) * 0.5f;
		frame.size.width = availableWidth * 0.70f;
		//Aspect ratio
		float pc = frame.size.width/oriWidth;	
		frame.size.height = frame.size.height * pc;
	}else{
		//Height is biggest, use 70% of the available height space (keep aspect ratio)
		float oriHeight = frame.size.height;
		float availableHeight = masterFrame.size.height - masterFrame.origin.y;
		frame.size.height = availableHeight * 0.70f;
		//Aspect ratio
		float pc = frame.size.height/oriHeight;	
		frame.size.width = frame.size.width * pc;
	}
	
	//Center at left half of the screen
    frame.origin.y = masterFrame.origin.y + ((masterFrame.size.height - frame.size.height) *0.5f);
    frame.origin.x = masterFrame.origin.x + (((masterFrame.size.width * 0.5f) - frame.size.width) * 0.5f);

    [_image setFrame: frame];

    // add it to our master layer
    [self addControl: _image];
	
	

    return ( self );
}

- (void) dealloc
{
    [_image release];


    [super dealloc];
}


- (id)layer{
	return _master;
}

- (void)activate{
	
}

- (void)willLoseFocus{

}

- (void)willRegainFocus{

}

- (void)willDeactivate{

}

- (void)deactivate{

}

- (BOOL)fadeLayerIn{
	return TRUE;
}

- (void)setDeletterboxAssetArtwork:(BOOL)fp8{

}


@end
